﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourBooking
    {
        public eTourBooking   Data;

        public TourBooking()
        {
            Data = new eTourBooking();
		}

        ~TourBooking()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cTourBooking objDAL = new cTourBooking();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
           cTourBooking objDAL = new cTourBooking();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
           cTourBooking objInfor = new cTourBooking(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourBookingID ;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cTourBooking objInfor = new cTourBooking();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        private void MappingData(cTourBooking objInfor)
        {
            objInfor.Adult = Data.Adult;
            objInfor.BookingDate = Data.BookingDate;
            objInfor.Child = Data.Child;
            objInfor.ContactAddress = Data.ContactAddress;
            objInfor.ContactEmail = Data.ContactEmail;
            objInfor.ContactFullname = Data.ContactFullname;
            objInfor.ContactPhone = Data.ContactPhone;
            objInfor.Kid = Data.Kid;
            objInfor.Status = Data.Status;
            objInfor.TourID = Data.TourID;

            objInfor.Duration = Data.Duration;
            objInfor.ExtraBed = Data.ExtraBed;
            objInfor.FinishedDate = Data.FinishedDate;
            objInfor.FullNameTitle = Data.FullNameTitle;
            objInfor.HotelStarRating = Data.HotelStarRating;
            objInfor.Nationality = Data.Nationality;
            objInfor.OtherRequest = Data.OtherRequest;
            objInfor.PaymentID = Data.PaymentID;
            objInfor.RoomTypeID = Data.RoomTypeID;
            objInfor.StartedDate = Data.StartedDate;
            objInfor.HowFindUs = Data.HowFindUs;
            objInfor.AirlineName = Data.AirlineName;
            objInfor.FlightTimeRef = Data.FlightTimeRef;
        }

        private void ConvertData(cTourBooking objInfor)
        {
            
            Data.Adult = objInfor.Adult;
            Data.BookingDate = objInfor.BookingDate;
            Data.Child = objInfor.Child;
            Data.ContactAddress = objInfor.ContactAddress;
            Data.ContactEmail = objInfor.ContactEmail;
            Data.ContactFullname = objInfor.ContactFullname;
            Data.ContactPhone = objInfor.ContactPhone;
            Data.Kid = objInfor.Kid;
            Data.Status = objInfor.Status;
            Data.TourID = objInfor.TourID;

            Data.Duration = objInfor.Duration;
            Data.ExtraBed = objInfor.ExtraBed;
            Data.FinishedDate = objInfor.FinishedDate;
            Data.FullNameTitle = objInfor.FullNameTitle;
            Data.HotelStarRating = objInfor.HotelStarRating;
            Data.Nationality = objInfor.Nationality;
            Data.OtherRequest = objInfor.OtherRequest;
            Data.PaymentID = objInfor.PaymentID;
            Data.RoomTypeID = objInfor.RoomTypeID;
            Data.StartedDate = objInfor.StartedDate;
            Data.HowFindUs = objInfor.HowFindUs;
            Data.AirlineName = objInfor.AirlineName;
            Data.FlightTimeRef = objInfor.FlightTimeRef;
        }
        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cTourBooking objDAL = new cTourBooking();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;

                objDAL.Save();
                nResult = objDAL.TourBookingID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public DataTable Search(int ItemID, int ItemView, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cTourBooking objDAL = new cTourBooking();
            tbResult = objDAL.Search(ItemID, ItemView, PageIndex, PageSize, ref PageCount);
            return tbResult;
        }
    }
}